package com.foreveross.service;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.foreveross.common.Constants;
import com.foreveross.dao.MessageDAO;
import com.foreveross.vo.Message;

@Service("messageService")
@Transactional
public class MessageService {

	@Resource
	MessageDAO messageDAO;
	
	public long getMessageListCount(String weixinId,String houseId,String title,String userId) throws Exception{
		return messageDAO.findMessageListCount(weixinId,houseId,title,userId);
	}

	public List<Message> getMessageList(String weixinId, String houseId,String title,int pageIndex,
			int pageSize,String userId) throws Exception {
		return messageDAO.findMessageList(weixinId,houseId,title,pageIndex,pageSize,userId);
	}
	
	public Message getMessageById(String id) throws Exception  {
		return (Message) messageDAO.findById(Message.class, id);
	}

	public void saveOrUpdate(Message message, String updateType) throws Exception {
		if (updateType.equals(Constants.UPDATE_ADD)) {
			message.setCreateDate(new Date());
			messageDAO.save(message);
		} else if (updateType.equals(Constants.UPDATE_EDIT)) {
			messageDAO.updateObject(message);
		}
	}
	
	public void deleteMessage(String ids) throws Exception{
		if(ids == null) return ;
		for(String id :ids.split(",")){
			messageDAO.deleteMessage(id);
		}
	}


}
